<!DOCTYPE html>
<html>
<head>
<title>Get HardWareID from MSC</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">-->
<link rel="stylesheet" href="/css/bootstrap.min.css">
<script src="/js/jquery.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
</head>
<body>
<?
	include "top.php";
	extract($_POST);
	extract($_GET);
	unset($_POST,$_GET);

	echo "<div class='container-fluid'>\n";
	echo "<div style='float:left'>\n";
	echo "<form action='msc_query.php?act=q' method='POST'>\n";
	echo "<strong>IP List:</strong>\n";
	echo "<select style='width:240px;' onchange=\"document.getElementById('ipAdd').value=this.value\" class='form-control'>\n";
	echo	"<option value='10.100.160.208'>10.100.160.208(TF$)</option>\n";
	echo	"<option value='10.100.160.219'>10.100.160.219(Maingear)</option>\n";
	echo	"<option value='10.100.160.202'>10.100.160.202(TFPC)</option>\n";
	echo	"<option value='10.100.160.216'>10.100.160.216(DNS)</option>\n";
	echo	"<option value='10.100.130.155'>10.100.130.155(TFSZ)</option>\n";
	echo	"<option value='10.100.160.215'>10.100.160.215(Haier)</option>\n";
	echo	"<option value='10.100.160.196'>10.100.160.196(火影)</option>\n";
	echo	"<option value='10.100.160.191'>10.100.160.191(ELU)</option>\n";
	echo "</select>\n";

		echo "<strong>IP ADDR:</strong>\n";
		if(isset($ip)) {
			echo "<input type='text' name='ip' id='ipAdd'  value='$ip' class='form-control'>\n";
		} else {
			echo "<input type='text' name='ip' id='ipAdd'  value='10.100.160.208' class='form-control'>\n";
		} 

		if(isset($isbound)) {
			echo "<strong><font color='blue'>只查BOUND: </font></strong><input type='checkbox' name='isbound' value='1' checked='checked'/>\n</br>";
			$kid="N/A";
		} else{
			echo "<strong>只查BOUND: </strong><input type='checkbox' name='isbound' value='1' />\n</br>";
		}

		echo "<strong>KEY  ID:</strong>\n";
		if(isset($kid)) {
			echo "<input type='text' name='kid' value='$kid' class='form-control'>\n";
		}else{
			echo "<input type='text' name='kid'  class='form-control'>\n";
		}

		echo "<button type='submit' class='btn btn-primary'>查询</button>\n";
		echo "</form>\n";

	if ($act='q' && $ip!='' && $kid!=''){
		$servername="DRIVER={SQL Server};SERVER=$ip;DATABASE=SmartClient";
		$conn=odbc_connect($servername,'thtfmes',"Mes&thtf",SQL_CUR_USE_ODBC);
		if (!$conn){
			echo "<font color='red'>Couldn't connect to SQL Server on $servername </font>";
		}else{
			$sql="	SELECT dbo.ProductKeyInfo.ProductKeyID, dbo.ProductKeyInfo.HardwareID,dbo.ProductKey.ProductKeyState,dbo.ProductKey.LicensablePartNumber
					FROM dbo.ProductKey INNER JOIN
						dbo.ProductKeyInfo ON dbo.ProductKey.ProductKeyID = dbo.ProductKeyInfo.ProductKeyID
					WHERE (dbo.ProductKey.MSFTProductKeyID = '$kid')";
			//$sql="select * from ProductKeyInfo where ProductKeyID='$kid'";
			
			if(isset($isbound)) {
				$sql = "select MSFTProductKeyID from ProductKey where ProductKeyStateID=3";
			}

			$exec=odbc_exec($conn, $sql);
			
			if(isset($isbound)) {
				echo "<textarea rows='20' cols='80'>";
				while (odbc_fetch_row($exec)){
					$MSKID=odbc_result($exec,"MSFTProductKeyID");
					echo "$MSKID\r\n";
				}
				echo "</textarea>";
			} else {
				if(odbc_fetch_row($exec)){
					print '<strong>Product Key ID:</strong><input type="text" value="'.odbc_result($exec,"ProductKeyID").'"  class="form-control" ><br \>';
					print '<strong>Key State: </strong><font color="red">'.odbc_result($exec,"ProductKeyState").'</font> ----> <strong>LicensablePartNumber:</strong> '.odbc_result($exec,"LicensablePartNumber").'<br \><br \>';
					print '<strong>HardwareID:</strong><textarea rows="8" cols="80"  class="form-control">'.odbc_result($exec,"HardWareID").'</textarea>';	
				}else{
					$sql="SELECT dbo.ProductKey.ProductKeyID,dbo.ProductKey.ProductKeyState
						FROM dbo.ProductKey WHERE dbo.ProductKey.MSFTProductKeyID = '$kid'";
					$exec=odbc_exec($conn, $sql);
					if(odbc_fetch_row($exec)){
						print '<strong>Product Key ID:</strong><input type="text" value="'.odbc_result($exec,"ProductKeyID").'"  class="form-control" ><br \>';
						print '<strong>Key State: </strong><font color="red">'.odbc_result($exec,"ProductKeyState").'</font> ----> <strong>LicensablePartNumber:</strong> '.odbc_result($exec,"LicensablePartNumber").'<br \><br \>';
						print '<strong>HardwareID:</strong><textarea rows="8" cols="80"  class="form-control">'.odbc_result($exec,"HardWareID").'</textarea>';	
					}
				}
			}
			odbc_close($conn);
		}
	}
?>
	</div>
</div>
<?
	include 'bottom.php';
?>
</body>
</html>